﻿
@{
    ViewBag.Title = "省份管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@model ProvinceDTO[]

<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote province_search">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal provinceAdd_btn">添加省</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后除新添加的文章外所有操作无效，关闭页面所有数据重置</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold"> @Model.Count() </span>条数据</span>
                </div>
            </blockquote>

            <!-- 操作日志 -->
            <div class="layui-form province_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                        <col>

                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </th>
                            <th>省ID</th>
                            <th>省名</th>
                            <th>创建时间</th>

                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody class="province_content">

                        @foreach (var province in Model)
                        {
                            <tr>
                                <td>
                                    <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                                </td>
                                <th>@province.Id</th>
                                <th>@province.Name</th>
                                <th>@province.CreateDateTime</th>

                                <td>
                                    <a class="layui-btn layui-btn-mini province_edit" data-id="@province.Id"><i class="iconfont icon-edit"></i> 编辑</a>
                                    <a class="layui-btn layui-btn-danger layui-btn-mini province_del" data-id="@province.Id">
                                        <i class="layui-icon"></i> 删除
                                    </a>
                                </td>
                            </tr>

                        }


                    </tbody>
                </table>
                <div class="larry-table-page clearfix">
                    <div id="page" class="page"></div>
                </div>
            </div>

        </div>
    </div>

</section>


@section FooterScript{
    <script type="text/javascript">

        var $;

        var appConfig = {
            name: "province",    @*需要和页面名称对应*@
            title: "省份",    @*显示的名称*@
            addUrl: "/Province/AddNew",   @*添加弹框的路径*@
            editUrl: "/Province/Edit?id=",
            $: "",
            layer: "",
            area: ['100%', '300px'],   //弹出层的宽高

            //批量删除Ajax
            batchDel: function (data) {     @*Array data 得到的是 需要删除的id*@
                $ = appConfig.$

                $.ajax({
                    url: "/Province/BatchDel",
                    method: "post",
                    dataType: "json",
                    data: { "provinceIds": data },    @*data要删除的数组*@
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", {
                                icon: 1, time: 2000, end: function () {
                                    location.reload();
                                }
                            });



                        } else {
                            appConfig.layer.msg("删除失败", {
                                icon: 5, time: 2000, end: function () {
                                    location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        appConfig.layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                                location.reload();
                            }
                        });
                    }
                });


                //todo:在此处添加批量删除记录的ajax



            },
            del: function (data) {
                $ = appConfig.$

                $.ajax({
                    url: "/Province/Delete/",
                    method: "post",
                    dataType: "json",
                    data: { "provinceId": data },
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", { icon: 1 });

                        } else {
                            appConfig.layer.msg("删除失败", { icon: 5 });
                        }
                    },
                    error: function () {
                        appConfig.layer.msg("删除失败", { icon: 5 });
                    }
                });

                //todo:在此处添加删除记录的ajax
            }
        };

    </script>
}
